<template>
	<view class="container">
		
		
		
		<!-- 就诊人 -->
		<view class="yy-pat-head">
			<view class="yy-pat-peoItem" @click="changeckeck(index,item.id)" v-for="(item,index) in peoList" :key="index">
				<text>{{item.name}}</text>
				<view class="yy-pat-peoItem-check" v-if="item.check == 1">
					<image src="../../static/icon_checked.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		
		
		
		<!-- 暂无就诊人 -->
		<view class="yy-pat-null" v-if="peoList.length == 0">
			<view class="yy-pat-nullImg">
				<image src="../../static/img_blank_people.png" mode="widthFix"></image>
			</view>
			<text class="yy-pat-nullText">还没有就诊人</text>
		</view>
		
		
		
		
		<!-- 新增 -->
		<view class="yy-pat-footer">
			<view class="yy-pat-footerNav" @click="addpatient">
				<view class="">
					
				</view>
				<text>新增就诊人</text>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '../../App.vue'
	export default{
		data(){
			return{
				currcheck:0,
				id :'',
				peoList:[],
				patientId:''
			}
		},
		onLoad(options) {
			this.patientId = options.patientId
			// console.log(o)
			// this.id = 0
			// this.changeckec()
		},
		onShow() {
			this.getpatient()
		},
		methods:{
			changeckeck(i,id){
				let peoList =this.peoList
				let patientName = '' 
				let patientId = ''
				peoList.forEach((item,index)=>{
					item.check = 0
					if(index == i){
						item.check = 1
						patientName = item.name
						patientId = item.id
					}
				})
				this.peoList = peoList
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							let pages = getCurrentPages();
							let prevPage = pages[pages.length - 2];
							console.log(prevPage)
							prevPage.patientName = patientName,
							prevPage.patientId = patientId
							uni.navigateBack({
								delta:1
							})
						},1300)
					}
				})
			},
			getpatient(){
				let that = this,
				data = {
					
				}
				app.post('api/user_member/getUserMemberList',data).then(res=>{
					if(res.code == 1&& res.data != ''){
						let peoList = res.data
						peoList.forEach((item,index)=>{
							item.check = 0
							if(that.patientId == item.id){
								item.check = 1
							}
						})
						this.peoList = peoList
					}else if(res.code == 0){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title: res.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			addpatient(){
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/yuyue/addPatient?status=0'
							})
						},1300)
					}
				})
			}
			// changeckec(){
			// 	let peoList =this.peoList
			// 	peoList.forEach(item=>{
			// 		item.check = 0
					
			// 		if(this.id != '' && this.id == item.id){
			// 			item.check = 1
			// 		}
			// 	})
			// 	this.peoList = peoList
			// 	console.log(peoList)
			// }
		}
	}
</script>

<style>
	@import url("../../common/yuyuepatient.css");
</style>
